package cn.pinming.chyn.tools.utils;

public class StringTools {
	
	public static boolean isEmpty(String s) {
		return s == null || s.length() == 0 ;
	}
	
	public static boolean isNotEmpty(String s) {
		return !isEmpty(s) ;
	}
	
	// 首字母小写
	public static String firstLower(String s) {
		return isEmpty(s) ? s : s.substring(0,1).toLowerCase() + (s.length() > 1 ? s.substring(1) : "") ;
	}
	
	// 首字母大写
	public static String firstUpper(String s) {
		return isEmpty(s) ? s : s.substring(0,1).toUpperCase() + (s.length() > 1 ? s.substring(1) : "") ;
	}

	// 蛇形命名法转驼峰命名法
	public static String snakeToCamel(String snake) {
		if (snake == null || snake.isEmpty()) {
			return snake;
		}
		StringBuilder camel = new StringBuilder();
		boolean nextUpper = false;
		for (char c : snake.toCharArray()) {
			if (c == '_') {
				nextUpper = true;
			} else if (nextUpper) {
				camel.append(Character.toUpperCase(c));
				nextUpper = false;
			} else {
				camel.append(c);
			}
		}
		return camel.toString();
	}

	// 驼峰命名法转蛇形命名法
	public static String camelToSnake(String camel) {
		if (camel == null || camel.isEmpty()) {
			return camel;
		}
		StringBuilder snake = new StringBuilder();
		for (int i = 0; i < camel.length(); i++) {
			char c = camel.charAt(i);
			if (Character.isUpperCase(c)) {
				if (i > 0) {
					snake.append("_");
				}
				snake.append(Character.toLowerCase(c));
			} else {
				snake.append(c);
			}
		}
		return snake.toString();
	}
	
	public static String concat(String ...args) {
    	StringBuffer s = new StringBuffer() ;
    	for(String arg : args) {
    		if(arg != null) {
    			s.append(arg) ;
    		}
    	}
    	return s.toString() ;
    }
}
